<!DOCTYPE html>
<html lang="en">
<title>标准课程库</title>
<#import "/layout/layout.html" as body/>
<@body.page>

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title overflow">
                    <h5 class="pull-left">标准课程列表</h5>
                    <a href="to_course_standard_add" class="btn btn-sm btn-primary pull-right">添加新类别</a>
                </div>
                <form class="form-inline" role="form" method="post" id="queryForm" action="to_course_standard_list">
                    <input type="hidden" name="page" id="page" value="${page!}"/>
                    <input type="hidden" name="size" id="size" value="${size!}"/>
                </form>
                <div class="ibox-content">
                    <div class="table-responsive">
                        <table class="table table-hover table-center dataTables-example">
                            <thead>
                            <tr>
                                <th>类别ID</th>
                                <th>类别名称</th>
                                <th>类别主管教练</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody id="courseStandardList">
                            </tbody>
                        </table>
                    </div>
                </div>
                <div class="ibox-footer overflow">
                    <h4 class="pull-left">合计：<span id="courseStandardCount">0</span>个类别</h4>

                    <div id="copot-page" class="pull-right"></div>
                </div>
            </div>
        </div>
    </div>
</div>


<script>

    $(document).ready(function () {
        courseStandardPage(1);
    });


    //分页方法
    function courseStandardPage(currentIndex) {
        var param = {
            "pageIndex": currentIndex,
            "pageSize": 10
        };
        $("#courseList").empty();
        $.ajax({
            url: "${baseUrl}system/course/course_standard_list",
            data: param,
            type: "POST",
            success: function (result) {
                var html = "";
                //分页
                new Page({
                    parent: $("#copot-page"),
                    nowPage: currentIndex,
                    pageSize: 10,
                    totalCount: result.courseStandardCount,
                    setting: {
                        defaultPage: 5,//默认显示可点击分页的个数
                        firstPageText: "首页",
                        prevPageText: "上一页",
                        nextPageText: "下一页",
                        lastPageText: "尾页"
                    },
                    callback: function (nowPage, totalPage) {
                        courseStandardPage(nowPage);
                    }
                });

                $("#courseStandardCount").text(result.courseStandardCount);

                $.each(result.courseStandardList, function (i, data) {
                    var status = "";
                    if (data.status) {
                        if (data.status === "1") {
                            status = "正常";
                        } else if (data.status === "4") {
                            status = "已删除";
                        } else {
                            status = data.status;
                        }

                    }
                    html += "<tr><td>" + data.id + "</td>";
                    html += "<td>" + data.name + "</td>";
                    html += "<td>" + data.manager + "</td>";
                    html += "<td>" + status + "</td>";
                    html += "<td>";
                    html += "<button type='button' onclick='editStandardCourse(" + data.id + ")' class='btn btn-default'><i class='fa fa-pencil'></i> 编辑</button>";

                    if(data.status === '1'){
                        html += "<button type='button' onclick='deleteStandardCourse("+data.id+")' class='btn btn-default'><i class='fa fa-trash-o'></i> 删除</button>";
                    }
                    html += "</td>";
                    html += "</tr>";
                });
                $("#courseStandardList").html(html);
            }
        });
    }
    //跳转编辑
    function editStandardCourse(id) {
        window.location = "to_course_standard_edit?id=" + id;
    }

    //删除
    function deleteStandardCourse(courseStandardId) {

        swal({
            title: "确定要删除吗?",
            text: "删除后不可恢复!",
            type: "warning",
            showCancelButton: true,
            cancelButtonText: "容我三思！",
            confirmButtonText: "删除!"
        }).then(function () {
            $.ajax({
                type: "post",
                url: "course_standard_delete",
                data: {"id": courseStandardId},
                success: function (result) {
                    if (result) {
                        swal("删除成功!", "页面即将重新加载,请稍后...", "success");
                        window.setTimeout(function () {
                            window.location.reload()
                        }, 1000);
                    }
                }
            });
        });
    }


</script>
</@body.page>
</html>